package com.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.pojo.Suppiler;
import com.service.SuppilerService;
import com.util.LayuiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@Transactional
@RequestMapping("/suppiler")
public class SuppilerController {
@Autowired
    public SuppilerService  suppilerService;

@RequestMapping("/list")
    @ResponseBody
    public String suppilerList(Integer sid,String scope){
    return JSON.toJSONString(LayuiTable.tableData(suppilerService.suppilerFindAll(sid,scope).size(),
            suppilerService.suppilerFindAll(sid,scope)), SerializerFeature.DisableCircularReferenceDetect);
}

    @RequestMapping("/add")
    @ResponseBody
    public String suppileradd(String suppilerlist){
        Map add= JSON.parseObject(suppilerlist);
        String firm= add.get("firm").toString();
        String province= add.get("province").toString();
        String city= add.get("city").toString();
        String county= add.get("county").toString();
        String sname= add.get("sname").toString();
        String phone= add.get("phone").toString();
        String scope= add.get("scope").toString();
        int a=suppilerService.suppilerInsert(new Suppiler(null,firm,province,city,county,sname,phone,scope));
        if (a==1){
            return "true";
        }else {
            return "false";
        }
    }

    @RequestMapping("/edit")
    @ResponseBody
    public String empedit(String suppilerlist){
        Map edit= JSON.parseObject(suppilerlist);
        Integer sid= Integer.valueOf(edit.get("sid").toString());
        String firm= edit.get("firm").toString();
        String province= edit.get("province").toString();
        String city= edit.get("city").toString();
        String county= edit.get("county").toString();
        String sname= edit.get("sname").toString();
        String phone= edit.get("phone").toString();
        String scope= edit.get("scope").toString();
        int a=suppilerService.suppilerUpdate(new Suppiler(sid,firm,province,city,county,sname,phone,scope));
        if (a==1){
            return "true";
        }else {
            return "false";
        }
    }

    @RequestMapping("/del")
    @ResponseBody
    public String empdel(Integer sid){
        int a=suppilerService.suppilerDelete(sid);
        if (a==1){
            return "true";
        }else {
            return "false";
        }
    }
}
